import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/frontpage',
    children: [{
      path: 'frontpage',
      name: 'Frontpage',
      component: () => import('@/views/frontpage/index'),
      meta: { title: '系统说明', icon: 'el-icon-s-home' }
    }]
  },
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '项目', icon: 'el-icon-menu' }
    }]
  },
  {
    path: '/usercenter',
    component: Layout,
    children: [{
      path: 'usercenter',
      name: 'UserCenter',
      component: () => import('@/views/usercenter/index'),
      meta: { title: '激活', icon: 'dashboard' }
    }]
  },
  {
    path: '/accounts',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Accounts',
        component: () => import('@/views/accounts/index'),
        meta: { title: 'TG账号', icon: 'form' }
      }
    ]
  },
  {
    path: '/proxy',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Proxy',
        component: () => import('@/views/proxy/index'),
        meta: { title: '代理配置', icon: 'form' }
      }
    ]
  },
  {
    path: '/sidekick',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Sidekick',
        component: () => import('@/views/sidekick/index'),
        meta: { title: 'Sidekick', icon: 'el-icon-game-sidekick' }
      }
    ]
  },
  {
    path: '/hamster',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Hamster',
        component: () => import('@/views/hamster/index'),
        meta: { title: 'Hamster', icon: 'el-icon-game-hamster' }
      }
    ]
  },
  {
    path: '/piggy',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Piggy',
        component: () => import('@/views/piggy/index'),
        meta: { title: 'Piggy', icon: 'el-icon-game-piggy' }
      }
    ]
  },
  {
    path: '/blum',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Blum',
        component: () => import('@/views/blum/index'),
        meta: { title: 'Blum', icon: 'el-icon-game-blum' }
      }
    ]
  },
  {
    path: '/tonstation',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Tonstation',
        component: () => import('@/views/tonstation/index'),
        meta: { title: 'Tonstation', icon: 'el-icon-game-tonstation' }
      }
    ]
  },
  {
    path: '/duckchain',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'DuckChain',
        component: () => import('@/views/duckchain/index'),
        // meta: { title: 'DuckChain', icon: 'el-icon-s-help' }
        meta: { title: 'DuckChain', icon: 'el-icon-game-duck' }
      }
    ]
  },
  {
    path: '/timefarm',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Timefarm',
        component: () => import('@/views/timefarm/index'),
        // meta: { title: 'DuckChain', icon: 'el-icon-s-help' }
        meta: { title: 'Timefarm', icon: 'el-icon-game-timefarm' }
      }
    ]
  },
  {
    path: '/tabizoo',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Tabizoo',
        component: () => import('@/views/tabizoo/index'),
        meta: { title: 'Tabizoo', icon: 'el-icon-game-tabizoo' }
      }
    ]
  },
  {
    path: '/cats',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Cats',
        component: () => import('@/views/cats/index'),
        meta: { title: 'Cats', icon: 'el-icon-game-cats' }
      }
    ]
  },
  {
    path: '/major',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Major',
        component: () => import('@/views/major/index'),
        meta: { title: 'Major', icon: 'el-icon-game-major' }
      }
    ]
  },
  {
    path: '/memefi',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Memefi',
        component: () => import('@/views/memefi/index'),
        meta: { title: 'Memefi', icon: 'el-icon-game-memefi' }
      }
    ]
  },
  {
    path: '/cows',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Cows',
        component: () => import('@/views/cows/index'),
        meta: { title: 'Cows', icon: 'el-icon-game-cows' }
      }
    ]
  },
  {
    path: '/tomarket',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Tomarket',
        component: () => import('@/views/tomarket/index'),
        meta: { title: 'Tomarket', icon: 'el-icon-game-tomarket' }
      }
    ]
  },
  // {
  //   path: '/vana',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Vana',
  //       component: () => import('@/views/vana/index'),
  //       // meta: { title: 'DuckChain', icon: 'el-icon-s-help' }
  //       meta: { title: 'Vana', icon: 'el-icon-game-vana' }
  //     }
  //   ]
  // },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
